load->helper('url'); // Only show install page if there is no lock if ($this->config->item('install') != 'no') { show_404(); } } /** * First Step * * We check if the server can be used to install nab */ function index() { if (is_really_writable($this->config->config_path) && ! @chmod($this->config->config_path, FILE_WRITE_MODE)) { show_error('config file is not writable'); } // Is there a database.php file? if (@include($this->config->database_path)) { // let's test if the data contained in the file was setup before if ($this->_test_mysql_connection($db[$active_group])) { redirect('install/step2'); } else { if (is_really_writable($this->config->database_path) === FALSE) { show_error('database config file is not writable'); } else { //we have the files but there is no connection redirect('install/step1'); } } } else { show_error('database config file does not exists'); } } /** * Start * * There is no connection but we have the files and we can write them */ function step1() { $this->form_validation->set_rules('host', 'Host', 'required'); $this->form_validation->set_rules('database', 'Database', 'required'); $this->form_validation->set_rules('user', 'Database User', 'required'); $this->form_validation->set_rules('pass', 'Database Pass', ''); if ($this->form_validation->run() == TRUE) { if($this->_setup_database()) { redirect('install/step2'); } } else { $data['msg'] = validation_errors('

', '

'); $data['title'] = 'Install Step 1'; $this->load->view('install/step1', $data); } } /** * Step2 * * Here you should add custom stuff (if a blog for example, set title, users, etc) */ function step2() { $this->form_validation->set_rules('title', 'Blog Title', 'required'); $this->form_validation->set_rules('user', 'Blog User', 'required'); $this->form_validation->set_rules('pass', 'Blog Pass', 'required'); if ($this->form_validation->run() == TRUE) { if($this->_install_database()) { redirect('install/finished'); } else { show_error('there was a problem installing the database'); } } else { $data['msg'] = validation_errors('

', '

'); $data['title'] = 'Install Step 2'; $this->load->view('install/step2', $data); } } /** * Finished * * Here you should add custom stuff (if a blog for example, set title, users, etc) */ function finished() { $data['title'] = 'Install Finished'; $this->load->view('install/finished', $data); } /** * DB Driver Test * * Test a given driver to ensure the server can use it. We'll also create the * database here if we need to. * * @access private * @param array * @return bool */ function _test_mysql_connection($config_db) { if(!is_array($config_db)) { $config_db = array(); $config_db['hostname'] = $this->input->post('host'); $config_db['username'] = $this->input->post('user'); $config_db['password'] = $this->input->post('pass'); $config_db['database'] = $this->input->post('database'); $config_db['dbdriver'] = 'mysql'; } // Unset any existing DB information unset($this->db); // Debugging to FALSE to avoid CI throwing errors if its wrong $config_db['db_debug'] = FALSE; // load based on custom passed information $this->load->database($config_db); if (is_resource($this->db->conn_id) OR is_object($this->db->conn_id)) { // There is a connection $this->load->dbutil(); // Now then, does the DB exist? if ($this->dbutil->database_exists($this->db->database)) { return TRUE; } else { $this->load->dbforge(); if ($this->dbforge->create_database($this->db->database)) { return TRUE; } else { return FALSE; } } } else { return FALSE; } } /** * Do Install */ function _install_database() { $this->load->database(); $this->load->dbforge(); $this->load->model('install_model'); $this->install_model->add_tables(); if ( ! $this->config->config_update(array('install'=>"locked"))) { show_error('could not update config file'); } @chmod($this->config->config_path, FILE_READ_MODE); @chmod($this->config->database_path, FILE_READ_MODE); return TRUE; } /** * Setup Database (only MySQL supported now) */ function _setup_database() { if (@include($this->config->database_path)) { if ($this->_test_mysql_connection($db[$active_group])) { return TRUE; } else { return FALSE; } } $_db['hostname'] = $this->input->post('host'); $_db['username'] = $this->input->post('user'); $_db['password'] = $this->input->post('pass'); $_db['database'] = $this->input->post('database'); // Update config/database.php file return $this->config->db_config_update($_db); } } /* End of file install.php */ /* Location: ./application/controllers/install.php */